
// MagicWandFrm.cpp : implementation of the CMagicWandFrame class
//

#include "stdafx.h"
#include "MagicWand.h"

#include "MagicWandFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CMagicWandFrame

static int gCreateNum = 0;

IMPLEMENT_DYNCREATE(CMagicWandFrame, CXtremChildFrame)

BEGIN_MESSAGE_MAP(CMagicWandFrame, CXtremChildFrame)
	ON_WM_CREATE()
	ON_WM_SIZE()
END_MESSAGE_MAP()

// CMagicWandFrame construction/destruction

CMagicWandFrame::CMagicWandFrame()
{
	// TODO: add member initialization code here
	++gCreateNum;
}

CMagicWandFrame::~CMagicWandFrame()
{
	--gCreateNum;
}


BOOL CMagicWandFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
	if( !CXtremChildFrame::PreCreateWindow(cs) )
		return FALSE;

	return TRUE;
}

// CMagicWandFrame diagnostics

#ifdef _DEBUG
void CMagicWandFrame::AssertValid() const
{
	CXtremChildFrame::AssertValid();
}

void CMagicWandFrame::Dump(CDumpContext& dc) const
{
	CXtremChildFrame::Dump(dc);
}
#endif //_DEBUG


int CMagicWandFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CXtremChildFrame::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here

	return 0;
}


void CMagicWandFrame::OnSize(UINT nType, int cx, int cy)
{
	CXtremChildFrame::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
}


// CreateRibbonBar
bool CMagicWandFrame::CreateRibbonBar(void)
{
	CXtremeMDIFrameWnd* pMainFrame = (CXtremeMDIFrameWnd*)AfxGetMainWnd();	
	CSysLocalResource res(theApp.m_hInstance);	
	CXTPCommandBars* pCommandBars = pMainFrame->GetCommandBars();
	if(gCreateNum > 1)
	{
		int count = pRibbonBar->GetTabCount();
		for(int i = 1 ; i< count; ++i)
		{
			CXTPRibbonTab* pTab = pRibbonBar->GetTab(i);
			if(pTab == pTabControl)
			{
				pRibbonBar->SetCurSel(i);
			}
		}
		return true;
	}
	pRibbonBar = (CXTPRibbonBar*)pCommandBars->GetAt(0);
	if (!pRibbonBar)
	{
		return false;
	}

	pTabControl = pRibbonBar->AddTab(ID_MAGIC_WAND);

	CXTPControl* pControl = NULL;
	CXTPRibbonGroup* pGroupFile = pTabControl->AddGroup(ID_FILE_ORDER);	
	pGroupFile->Add(xtpControlButton, ID_OPEN_FILE);
	pGroupFile->Add(xtpControlButton, ID_FILE_RESET);
	pGroupFile->Add(xtpControlButton, ID_CLOSE_FILE);

	pGroupFile = pTabControl->AddGroup(ID_PICTURE_ORDER);	
	pControl = pGroupFile->Add(xtpControlButton, ID_NARROW_1);
	pControl->SetBeginGroup(TRUE);
	pGroupFile->Add(xtpControlButton, ID_NARROW_2);
	pGroupFile->Add(xtpControlButton, ID_NARROW_3);
	pGroupFile->Add(xtpControlButton, ID_NARROW_4);

	//pControl = pGroupFile->Add(xtpControlButton, ID_FUN_1);
	//pControl->SetBeginGroup(TRUE);
	//pGroupFile->Add(xtpControlButton, ID_FUN_2);
	//pGroupFile->Add(xtpControlButton, ID_FUN_3);
	//pGroupFile->Add(xtpControlButton, ID_FUN_4);

	pGroupFile = pTabControl->AddGroup(ID_DEALWITH_RECT);	
	pControl = pGroupFile->Add(xtpControlButton, ID_PICTURE_SELECT);
	pControl->SetBeginGroup(TRUE);
	pGroupFile->Add(xtpControlButton, ID_IMAGE_RECT);

	pGroupFile = pTabControl->AddGroup(ID_FUNCTION_1);
	pGroupFile->Add(xtpControlButton, ID_PICTURE_CONFIG);
	pGroupFile->Add(xtpControlButton, ID_PICTURE_MAGIC);


	pGroupFile = pTabControl->AddGroup(ID_FUNCTION_2);
	pGroupFile->Add(xtpControlButton, ID_PICTURE_CANNY);
	pGroupFile->Add(xtpControlButton, ID_PICTURE_CONNECTED);
	pGroupFile->Add(xtpControlButton, ID_PICTURE_IMAGE);

	pGroupFile = pTabControl->AddGroup(ID_FUNCTION_3);
	pGroupFile->Add(xtpControlButton, ID_HLV_IMAGE);

	pGroupFile = pTabControl->AddGroup(ID_FUNCTION_4);
	pGroupFile->Add(xtpControlButton, ID_FUNCTION_CONFIG);
	pGroupFile->Add(xtpControlButton, ID_FUNCTION_MAGIC);

	int count = pRibbonBar->GetTabCount();
	for(int i = 1 ; i< count; ++i)
	{
		CXTPRibbonTab* pTab = pRibbonBar->GetTab(i);
		if(pTab == pTabControl)
		{
			pRibbonBar->SetCurSel(i);
		}
	}
	pRibbonBar->EnableFrameTheme();
	return true;
}

// LoadIcons
void CMagicWandFrame::LoadIcons(void)
{
	CXtremeMDIFrameWnd* pMainFrame = (CXtremeMDIFrameWnd*)AfxGetMainWnd();	
	CSysLocalResource res(theApp.m_hInstance);	
	CXTPCommandBars* pCommandBars = pMainFrame->GetCommandBars();
	pCommandBars->GetImageManager()->SetIcons(IDR_LARGE_FILE);
	pCommandBars->GetImageManager()->SetIcons(IDR_LARGE_ORDER);
	//UINT mediaplay[] = {ID_MEDIA_PLAY, ID_MEDIA_STOP, ID_MEDIA_SHOW };
	//pCommandBars->GetImageManager()->SetIcons(ID_MEDIA_PLAY, mediaplay, _countof(mediaplay), CSize(32, 32));
	//UINT mediastop[] = {ID_MEDIA_STOP, 1 };
	//pCommandBars->GetImageManager()->SetIcons(ID_MEDIA_STOP, mediaplay, _countof(mediaplay), CSize(256, 256));

}